home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / Virtual User 1.0 / Example Scripts / DrawShapesStress / DrawShapesStress.vu next >
Text File  |  1991-01-25  |  13KB  |  365 lines

  1. #
  2. #    File DrawShapes.vu 
  3. #
  4. #    Contains:    A test script for DrawShapesVU, the MacApp DrawShapes example program which 
  5. #                has been built with the Agent VU hook for MacApp.  The script selects
  6. #                a random shape to draw, draws it to a random size in a random location within
  7. #                the window, colors and shades it randomly, and then moves it to a random location in
  8. #                the window.  It selects a random editing operation after every "Shapes_per_edit" 
  9. #                shapes are drawn. A number of shapes equal to the global variable "Num_shapes" 
  10. #                (set to a default of 12) is drawn before the script stops.
  11. #
  12. #                This script also has the option of creating output which will recreate the exact
  13. #                actions of a script execution in the form of another VU script.  In other words, a 
  14. #                series of println statements will be executed in the script which will effectively
  15. #                build another VU script.  This script built from output statements will be a series
  16. #                of VU commands with all the variables instantiated. An execution of the output
  17. #                script should duplicate the actions of the parent script.  This is very useful
  18. #                for the purposes of reproducibility. If a script of random actions causes a crash 
  19. #                in the application, the output script can retrace the steps of the script which 
  20. #                caused the crash.
  21. #            
  22. #                The creation of this script as output can be enabled by setting the global
  23. #                Echo_on to true (default is true).
  24. #                
  25. #
  26. #    Starting Configuration:    In order for the script to run properly, the target should be running
  27. #                            the DrawShapesVU MacApp demo program 1.0d1, including in the VU package.
  28. #                            
  29. #                            THIS SCRIPT WILL NOT WORK WHEN RUNNING AGAINST DrawShapesVU UNDER THE
  30. #                            THE CURRENT SEEDED ALPHA RELEASE OF SYSTEM 7.0.
  31. #                            
  32. #
  33. #    Conventions:    Global variables begin with a capital letter
  34. #
  35. #    Written by:    Jim Schneider
  36. #
  37. #    Copyright:    © 1990 by Apple Computer, Inc., all rights reserved.
  38. #
  39. #    Change History:
  40. #
  41. #         8/15/90    JAS        added echo option to build "retrace" script as output
  42. #    
  43. #         8/15/90    JAS        took out window scrolling, inserted window drag to known location
  44. #
  45. #         5/15/90    JAS        take out infinite loop.    
  46. #
  47. #         5/2/90        JAS        creation
  48. #
  49.  
  50.  
  51.  
  52. # ********************************************************************************************
  53. #Select the DrawShapes tool from the pallette
  54. task select_pallette_tool(the_tool) begin
  55.     global Echo_on;
  56.     global Wind_rect;
  57.     
  58.     x:=Wind_rect[1]-20;
  59.     y:=Wind_rect[2]+20+(40*(the_tool-1));
  60.     move absolute: {x,y};                if Echo_on println "move absolute: ∂{{x},{y}∂};";
  61.     click;                                if Echo_on println "click;";
  62. end;
  63.  
  64.  
  65. # ********************************************************************************************
  66. # Pick a random color from the color picker dialog.
  67. task handle_color_picker() begin
  68.     global Echo_on;
  69.     global Max_scroll_value;
  70.     global Rel_color_picker_center;
  71.     global Picker_radius;    
  72.     
  73.     match[window o:1 r:?color_picker_w_rect];
  74.     scroll_value := random(1,Max_scroll_value);
  75.     scroll [scrollbar w:[window o:1]] absolute:{scroll_value,Max_scroll_value};
  76.     if Echo_on
  77.         println "scroll [scrollbar w:[window o:1]] absolute:∂{{scroll_value},{Max_scroll_value}∂};";
  78.     wait(1);
  79.     if Echo_on 
  80.         println "wait(1);";
  81.     color_picker_center := {Rel_color_picker_center[1] + color_picker_w_rect[1],Rel_color_picker_center[2] + color_picker_w_rect[2]};
  82.     x_offset := random(0,(Picker_radius*2)) - Picker_radius;
  83.     y_offset := random(0,(Picker_radius*2)) - Picker_radius;
  84.     while ((x_offset*x_offset) + (y_offset*y_offset) > Picker_radius*Picker_radius) begin
  85.         x_offset := random(0,(Picker_radius*2)) - Picker_radius;
  86.         y_offset := random(0,(Picker_radius*2)) - Picker_radius;
  87.     end;
  88.     x:=color_picker_center[1]+x_offset;
  89.     y:=color_picker_center[2]+y_offset;
  90.     move absolute: {x,y};                        if Echo_on println "move absolute: ∂{{x},{y}∂};";
  91.     wait(1);                                    if Echo_on println "wait(1);";
  92.     click;                                        if Echo_on println "click;";
  93.     select[button t:'OK' w:[window o:1]]!;        if Echo_on 
  94.                                                    println "select[button t:'OK' w:[window o:1]]!;";
  95. end;
  96.     
  97.  
  98. # ********************************************************************************************
  99. # Color the selected shape a random color from Colors menu.  Screen out the '---' item.
  100. task color_shape() begin
  101.     global Echo_on;
  102.     global Num_colors;
  103.     global Color_sep_item;
  104.     global Pick_color_item;    
  105.     
  106.     the_color := random(1,Num_colors);
  107.     if (the_color = Color_sep_item) 
  108.         while (the_color = Color_sep_item) 
  109.             the_color := random(1,Num_colors);    
  110.     select [menuitem m:[menu t:"Colors"] o:the_color];
  111.     if Echo_on 
  112.         println "select [menuitem m:[menu t:'Colors'] o:{the_color}];";
  113.     if (the_color = Pick_color_item)
  114.         handle_color_picker();
  115. end;
  116.  
  117.  
  118.  
  119. # ********************************************************************************************
  120. # Shade the selected shape a random shade from the Shades menu
  121. task shade_shape() begin
  122.     global Echo_on;
  123.     global Shade_menu_posn;
  124.     global Shade_cell_size;    
  125.     
  126.     the_row := random(1,2);
  127.     the_column := random(0,2);
  128.     x:=Shade_menu_posn[1];
  129.     y:=Shade_menu_posn[2];
  130.     move a: {x,y};                    if Echo_on println "move a: ∂{{x},{y}∂};";
  131.     pressMouse;                        if Echo_on println "pressMouse;";
  132.     wait(1);                        if Echo_on println "wait(1);";
  133.     x:=Shade_cell_size*the_column;
  134.     y:=Shade_cell_size*the_row;
  135.     move relative: {x,y};            if Echo_on println "move relative: ∂{{x},{y}∂};";
  136.     wait(1);                        if Echo_on println "wait(1);";    
  137.     releaseMouse;                    if Echo_on println "releaseMouse;";
  138. end;
  139.  
  140.  
  141. # ********************************************************************************************
  142. # Return true if a shape was just drawn (we know this by seeing if the 'Colors' menu is enabled).  
  143. # Otherwise, return false.
  144. task test_shape_drawn() begin
  145.     match[menu t:'Colors' e:?enabled]!;
  146.     return(enabled);
  147. end;
  148.  
  149.  
  150. # ********************************************************************************************
  151. # Select a random shape to draw from pallette and draw it at a random position.  Size it to a random
  152. # size.  Return the coordinates of the shape's rectangle.
  153. task draw_shape() begin
  154.     global Echo_on;
  155.     global Rect;
  156.     global Oval;
  157.     global Thick_rect;                        
  158.     global Wind_rect;
  159.     
  160.     prev_speed := mouseSpeed(4);            if Echo_on println "prev_speed := mouseSpeed(4);";
  161.     the_tool := random(Rect,Thick_rect);    
  162.     select_pallette_tool(the_tool);
  163.     x_coord1 := random(Wind_rect[1],Wind_rect[3]);
  164.     y_coord1 := random(Wind_rect[2],Wind_rect[4]);
  165.     move absolute: {x_coord1,y_coord1};        if Echo_on println
  166.                                                "move absolute: ∂{{x_coord1},{y_coord1}∂};";
  167.     wait(1);                                if Echo_on println "wait(1);";
  168.     pressMouse;                                if Echo_on println "pressMouse;";
  169.     x_coord2 := random(Wind_rect[1],Wind_rect[3]);
  170.     y_coord2 := random(Wind_rect[2],Wind_rect[4]);
  171.     move absolute: {x_coord2,y_coord2};        if Echo_on 
  172.                                                println "move absolute: ∂{{x_coord2},{y_coord2}∂};";
  173.     wait(1);                                if Echo_on println "wait(1);";
  174.     releaseMouse;                            if Echo_on println "releaseMouse;";
  175.     mouseSpeed(prev_speed);                    if Echo_on println "mouseSpeed({prev_speed});";
  176.     return({x_coord1,y_coord1,x_coord2,y_coord2});
  177. end;
  178.  
  179.  
  180. # ********************************************************************************************
  181. # Move the most current shape to a random position.  Pass back new shape rectangle.
  182. task move_shape() begin
  183.     global Echo_on;
  184.     global Arrow;
  185.     global Wind_rect;
  186.     global Shape_rect;
  187.     
  188.     x_coord := random(Wind_rect[1],Wind_rect[3]);
  189.     y_coord := random(Wind_rect[2],Wind_rect[4]);
  190.     select_pallette_tool(Arrow);
  191.     x:=(Shape_rect[1]+Shape_rect[3])/2;
  192.     y:=(Shape_rect[2]+Shape_rect[4])/2;
  193.     move absolute: {x,y};                 if Echo_on println "move absolute: ∂{{x},{y}∂};";
  194.     pressMouse;                            if Echo_on println "pressMouse;";
  195.     wait(1);                            if Echo_on println"wait(1);";
  196.     move absolute: {x_coord,y_coord};    if Echo_on println "move absolute: ∂{{x_coord},{y_coord}∂};";
  197.     wait(1);                            if Echo_on println"wait(1);";
  198.     releaseMouse;                        if Echo_on println"releaseMouse;";
  199.     shape_width := Shape_rect[3]-Shape_rect[1];
  200.     shape_height := Shape_rect[4] - Shape_rect[2];
  201.     return({x_coord-(shape_width/2),y_coord-(shape_height/2),x_coord+(shape_width/2),y_coord+(Shape_height/2)});
  202. end;
  203.     
  204.  
  205. # ********************************************************************************************
  206. # Select random item from edit menu and then possibly do something else, depending on what item 
  207. # was selected.  Screen out the "---" items.
  208. task do_some_editing() begin
  209.     global Echo_on;
  210.     global Shape_rect;
  211.     global Arrow;
  212.     global Num_edit_items;
  213.     global Undo_item;
  214.     global Edit_sep_item1;
  215.     global Cut_item;
  216.     global Copy_item;
  217.     global Paste_item;
  218.     global Clear_item;
  219.     global SelectAll_item;
  220.     global Edit_sep_item2;
  221.     global ShowClipboard_item;
  222.     
  223.     the_item := random(1,Num_edit_items);
  224.     while (not ((the_item = Edit_sep_item1) or (the_item = Edit_sep_item2)))
  225.         the_item := random(1,Num_edit_items);
  226.     match [menuitem m:[menu t:'Edit'] o:the_item e:?enabled];
  227.     while (not enabled) begin
  228.         the_item := random(1,Num_edit_items);
  229.         match [menuitem m:[menu t:'Edit'] o:the_item e:?enabled];
  230.     end;
  231.     select [menuitem m:[menu t:'Edit'] o:the_item]!;
  232.     if Echo_on 
  233.         println "select [menuitem m:[menu t:'Edit'] o:{the_item}]!;";
  234.     if ((the_item = Cut_item) or (the_item = Copy_item)) begin
  235.         select [menuitem t:'Paste' m:[menu t:'Edit']]!;
  236.         if Echo_on 
  237.             println "select [menuitem t:'Paste' m:[menu t:'Edit']]!;";
  238.     end;
  239.     else if (the_item = SelectAll_item) begin # move everything 50 pixels right or left, up or down
  240.         x_coord := 50 - random(1,100);
  241.         y_coord := 50 - random(1,100);
  242.         select_pallette_tool(Arrow);
  243.         x := (Shape_rect[1]+Shape_rect[3])/2;
  244.         y := (Shape_rect[2]+Shape_rect[4])/2;
  245.         move absolute: {x,y};                 if Echo_on println "move absolute: ∂{{x},{y}∂};";
  246.         pressMouse;                         if Echo_on println "pressMouse;";
  247.         wait(1);                             if Echo_on println "wait(1);";
  248.         move relative: {x_coord,y_coord};    if Echo_on 
  249.                                                 println "move relative: ∂{{x_coord},{y_coord}∂};";
  250.         wait(1);                            if Echo_on println "wait(1);";
  251.         releaseMouse;                        if Echo_on println "releaseMouse;";
  252.     end;
  253.     else if (the_item = ShowClipboard_item) begin
  254.         wait(1);                            if Echo_on println "wait(1);";
  255.         close [window o:1];                    if Echo_on println "close [window o:1];";
  256.     end;
  257. end;
  258.     
  259.         
  260. # ********************************************************************************************
  261. # clean up the DrawShapes window
  262. task clean_up_window() begin
  263.     global Echo_on;
  264.     
  265.     match [menuitem t:"Select All" m:[menu t:"Edit"] e:?enabled];
  266.     if (enabled) begin
  267.         select[menuitem t:"Select All" m:[menu t:"Edit"]];
  268.         if Echo_on 
  269.             println 'select[menuitem t:"Select All" m:[menu t:"Edit"]];';
  270.         select[menuitem t:"Clear" m:[menu t:"Edit"]];
  271.         if Echo_on 
  272.             println 'select[menuitem t:"Clear" m:[menu t:"Edit"]];';
  273.     end;
  274. end;
  275.  
  276.  
  277. # ********************************************************************************************
  278. # Get the rectangle representing the DrawShape's window content region
  279. task get_wind_cnt_rect() begin
  280.     global Pix_left;
  281.     global Pix_top;        
  282.     global Pix_right;
  283.     global Pix_bottom;
  284.     
  285.     match [window o:1 r:?window_rect]!;
  286.     return({window_rect[1]+Pix_left,window_rect[2]+Pix_top,window_rect[3]-Pix_right,window_rect[4]-Pix_bottom});
  287. end;
  288.  
  289.  
  290. #####   EXECUTION STARTS HERE  ######
  291.     
  292. # make this true if you want record of scripts actions in VU scripting languare
  293. # printed to standard output
  294. Echo_on                     := true;
  295.  
  296. # variable Num_shapes determines number of shapes drawn
  297. Num_Shapes                := 12; 
  298.  
  299. # number of shapes to draw before a random editing operation takes place
  300. Shapes_per_edit            := 3;
  301.  
  302. # indices into pallette
  303. Arrow                    := 1;
  304. Rect                    := 2;
  305. Oval                    := 3;
  306. Thick_rect                := 4;
  307.  
  308. # misc. globals
  309. Color_sep_item             := 8;
  310. Pick_color_item         := 9;
  311. Max_scroll_value         := 32767;
  312. Rel_color_picker_center := {293,137};
  313. Picker_radius             := 100;
  314. Shade_menu_posn            := {125,10};
  315. Shade_cell_size            := 25;
  316.  
  317. # pixels between window rect and content rect
  318. Pix_top                    := 21;
  319. Pix_left                := 41;
  320. Pix_bottom                := 17;
  321. Pix_right                := 17;
  322.  
  323. #edit menu items
  324. Num_edit_items             := 9;
  325. Undo_item                := 1;
  326. Edit_sep_item1            := 2;
  327. Cut_item                := 3;
  328. Copy_item                := 4;
  329. Paste_item                := 5;
  330. Clear_item                := 6;
  331. SelectAll_item            := 7;
  332. Edit_sep_item2            := 8;
  333. ShowClipboard_item        := 9;
  334.  
  335. match [menu t:"Colors" i:?Item_list]!;
  336. Num_colors := card(Item_list);        # get number of items in Colors menu
  337. match [menu t:"edit" i:?Item_List]!;
  338. Num_edit_items := card(Item_list);    # get number of items in Edit menu;
  339.  
  340. clean_up_window();
  341.  
  342. # this is done to ensure that absolute moves in output script will match those made in 
  343. # running this script
  344. drag [window o:1] a:{5,25};            
  345. if Echo_on
  346.     println 'drag [window o:1] a:{5,25};';
  347.  
  348. Wind_rect := get_wind_cnt_rect();    # get window's content rectangle
  349.  
  350. for i := 1 to Num_shapes begin
  351.     Shape_rect := draw_shape();
  352.     if test_shape_drawn() begin
  353.         color_shape();
  354.         shade_shape();
  355.         Shape_rect := move_shape();
  356.         if ((i mod Shapes_per_edit) = 0)
  357.             do_some_editing();
  358.     end;
  359. end;
  360.  
  361.  
  362.  
  363.  
  364.  
  365.